package com.eachann.privacypolicy.sample

import android.content.DialogInterface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.eachann.privacypolicy.library.PrivacyPolicyHelper
import com.eachann.privacypolicy.library.PrivacyPolicyDialog

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        if (!PrivacyPolicyHelper.isAgree(this)) {
            showDialog()
        }

    }

    private fun showDialog() {
        val builder = PrivacyPolicyDialog.Builder(this)
        builder.setCancelable(true)
        builder.setTitle("个人信息保护指引")
        builder.setMessage(
            "我们会遵循隐私政策收集,使用信息,但不会超过隐私条款内的条例越权强制收集其他信息。\n\n" +
                    "GPS,摄像头,麦克风,相册权限均不会默认开启,只有经过明示授权才会在为实现功能或服务时使用,不会在功能或服务不需要时而通过您授权的权限搜集信息。\n"
        )
        builder.setPositiveButtonBackground(R.drawable.drawable_custom_button_bg)
        builder.setPositiveButton(
            "同意并使用",
            listener = DialogInterface.OnClickListener { dialog, _ ->
                dialog.dismiss()
            })
        builder.setNeutralButton(
            "查看隐私政策 >",
            listener = DialogInterface.OnClickListener { _, _ ->
                PrivacyPolicyHelper.show(this@MainActivity, "https://privacy.qq.com/")
            })
        builder.show()
    }

    fun clickDialog(view: View) {
        if (!PrivacyPolicyHelper.isAgree(this)) {
            showDialog()
        }
    }

    fun clickButton(view: View) {
        PrivacyPolicyHelper.show(this@MainActivity, "https://privacy.qq.com/")
    }
}
